home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
X11
/
lib
/
spin.c
< prev
Wrap
C/C++ Source or Header
|
1995-05-03
|
4KB
|
134 lines
/*************************************************************************
* *
* Copyright (c) 1992, 1993 Ronald Joe Record *
* *
* All rights reserved. No part of this program or publication may be *
* reproduced, transmitted, transcribed, stored in a retrieval system, *
* or translated into any language or computer language, in any form or *
* by any means, electronic, mechanical, magnetic, optical, chemical, *
* biological, or otherwise, without the prior written permission of: *
* *
* Ronald Joe Record (408) 458-3718 *
* 212 Owen St., Santa Cruz, California 95062 USA *
* *
*************************************************************************/
#include <X11/Xlib.h>
#ifdef USE_DELAY
#include <signal.h>
#include <sys/time.h>
static int timerdone;
static void onalarm() {
timerdone = 1;
}
/*******/
void Timer(n) /* waits for 'n' milliseconds (from xv-2.21 source) */
int n;
/*******/
{
long usec;
#ifdef HAS_ITIMER
struct itimerval it;
#endif
if (!n) return;
usec = (long) n * 1000;
#ifdef HAS_ITIMER
memset(&it, 0, sizeof(it));
if (usec>=1000000L) { /* more than 1 second */
it.it_value.tv_sec = usec / 1000000L;
usec %= 1000000L;
}
it.it_value.tv_usec = usec;
#endif
timerdone=0;
signal(SIGALRM,onalarm);
#ifdef HAS_ITIMER
setitimer(ITIMER_REAL, &it, (struct itimerval *)0);
while (1) {
/* sigblock(sigmask(SIGALRM)); note: have to block, so that ALRM */
if (timerdone) break; /* doesn't occur between 'if (timerdone)' */
else sigpause(0); /* and calling sigpause(0) */
}
/* sigblock(0); turn ALRM blocking off */
signal(SIGALRM,SIG_DFL);
#else
nap((long)n);
#endif
}
#endif /*USE_DELAY */
void
Spin(display, colormap, colors, start_color, num_colors, delay, dir)
Display *display;
Colormap colormap;
XColor *colors;
int start_color, num_colors;
short dir, delay;
{
static short i;
static long tmpxcolor;
while (!XPending(display)) {
if (dir) {
tmpxcolor = colors[start_color].pixel;
for (i=start_color;i<num_colors-1;i++)
colors[i].pixel = colors[i+1].pixel;
colors[num_colors-1].pixel = tmpxcolor;
}
else {
tmpxcolor = colors[num_colors-1].pixel;
for (i=num_colors-1;i>start_color;i--)
colors[i].pixel = colors[i-1].pixel;
colors[start_color].pixel = tmpxcolor;
}
XStoreColors(display, colormap, colors, num_colors);
#ifdef USE_DELAY
Timer(delay);
#endif
}
}
void
DemoSpin(display, colormap, colors, start_color, num_colors, delay, factor)
Display *display;
Colormap colormap;
XColor *colors;
int start_color, num_colors;
short delay, factor;
{
static short i, j;
long tmpxcolor;
for (j=0;j<factor*num_colors;j++) {
tmpxcolor = colors[start_color].pixel;
for (i=start_color;i<num_colors-1;i++)
colors[i].pixel = colors[i+1].pixel;
colors[num_colors-1].pixel = tmpxcolor;
XStoreColors(display, colormap, colors, num_colors);
#ifdef USE_DELAY
Timer(delay);
#endif
}
for (j=0;j<factor*num_colors;j++) {
tmpxcolor = colors[num_colors-1].pixel;
for (i=num_colors-1;i>start_color;i--)
colors[i].pixel = colors[i-1].pixel;
colors[start_color].pixel = tmpxcolor;
XStoreColors(display, colormap, colors, num_colors);
#ifdef USE_DELAY
Timer(delay);
#endif
}
}